-- +goose Up
-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS users
(
    id                 uuid PRIMARY KEY DEFAULT gen_random_uuid(),
    email              VARCHAR(32) UNIQUE NOT NULL,
    encrypted_password VARCHAR            NOT NULL,
    created_at         TIMESTAMP        DEFAULT CURRENT_TIMESTAMP,
    updated_at         TIMESTAMP        DEFAULT CURRENT_TIMESTAMP
);

CREATE OR REPLACE FUNCTION before_update_users_trigger_fnc() RETURNS TRIGGER AS
$$
BEGIN
    new.updated_at := current_timestamp;
    RETURN new;
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE TRIGGER users_before_update_trigger
    BEFORE UPDATE
    ON users
    FOR EACH ROW
EXECUTE PROCEDURE before_update_users_trigger_fnc();

-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TRIGGER IF EXISTS users_before_update_trigger ON users;
DROP FUNCTION IF EXISTS before_update_users_trigger_fnc();
DROP TABLE IF EXISTS users;
-- +goose StatementEnd